package controller;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;

import dao.PaisDao;
import dao.PaisDaoImpl;

import model.Pais;

public class PaisesTag extends SimpleTagSupport {

	@Override
	public void doTag() throws JspException, IOException {
		List<Pais> listaPais = new ArrayList<Pais>();
		PaisDao pDao = new PaisDaoImpl();
		JspWriter out = getJspContext().getOut();
		try {
			listaPais = pDao.listaPaises();
			for (Pais p : listaPais){
				StringBuffer linha = new StringBuffer();
				linha.append("<option value=");
				linha.append("\"");
				linha.append(p.getId());
				linha.append("\"");
				linha.append(">");
				linha.append(p.getNome());
				linha.append("</option>");
				out.println(linha.toString());
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
